package cn.lingyangwl.agile.pay.common.config;

import cn.lingyangwl.agile.pay.common.model.mq.ErrorMQ;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.retry.MessageRecoverer;
import org.springframework.amqp.rabbit.retry.RepublishMessageRecoverer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author shenguangyang
 */
@Configuration
public class PayMqErrorConfig {

    @Resource
    private RabbitTemplate rabbitTemplate;


    /**
     * 消息重试一定次数后，用特定的routingKey转发到指定的交换机中，方便后续排查和告警
     */
    @Bean
    public MessageRecoverer messageRecoverer() {
        return new RepublishMessageRecoverer(rabbitTemplate, ErrorMQ.EXCHANGE, ErrorMQ.KEY);
    }
}
